/*
 * @Author: szx
 * @Date: 2022-03-16 16:05:40
 * @LastEditTime: 2022-03-16 16:05:40
 * @Description:
 * @FilePath: \learn\手撸JS源码\Object_create.js
 */
//Object.prototype.myCreate = function (proto) {
Object.myCreate = function (proto) {
    //这里应该用静态方法，而不是原型链
    if (typeof proto !== 'object' && typeof proto !== 'function') {
        throw new TypeError('Object prototype may only be an Object: ' + proto);
    } else if (proto === null) {
        throw new Error("This browser's implementation of Object.create is a shim and doesn't support 'null' as the first argument.");
    }
    // 创建一个空函数并将其 prototype 指向 proto
    function F() {}
    F.prototype = proto;

    // 返回一个新的实例对象，这样实例对象就能够访问到 proto 及其原型链上的属性和方法了
    return new F();
};
